<style lang="less">
@import "@/styles/table-common.less";
.btn-box{
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span{
    margin-left: 15px;
  }
}
.detail-modal{
  .form{
    div{
      display: flex;
      margin-bottom: 10px;
      span{
        width: 130px;
      }
      input{
        flex: 1;
        border: 1px solid #e8eaec;
        outline: none;
        text-indent: 16px;
        color: #515a6e;
      }
    }
  }
  .refund-num{
    margin-top: 15px;
  }
}

</style> 
<template>
  <div class="search">
    <Card>
      <Row class="operation">
        <Button @click="add" type="primary" icon="md-add">添加</Button>
      </Row>
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
        <!-- <template slot-scope="{ row }" slot="print">{{ row.print.serialNo }}</template> -->
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
      
    </Card>
    <addEdit
      :data="form"
      :type="showType"
      :idenList="idenList"
      v-model="showUser"
      @on-submit="getDataList"
    />
    
  </div>
</template>

<script>
import {
  getIdenType,
  getScParkRoleByCondition,
  scRuleGuideUpdStatu,

  getScRuleGuideByCondition
} from "@/api/index";

import { shortcuts } from "@/libs/shortcuts";
import {publicFun} from '@/libs/publicFun'
import addEdit from "./addEdit.vue";
export default {
  name: "user-manage",
  components: {
    addEdit,
  },
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: '',
      openSearch: true,
      idenList: [], //身份类型
      options: {
        shortcuts: shortcuts,
      },
      searchForm: {
        pageNumber: 1,
        pageSize: '10',
        sort: "createTime",
        order: "desc",
      },
      columns: [
        {
          title: "id",
          key: "id",
          minWidth: 220,
          align: "center",
        },
        {
          title: "规则说明",
          key: "remark",
          minWidth: 180,
          align: "center",
        },
        {
          title: "创建时间",
          key: "createTime",
          minWidth: 180,
          align: "center",
        },
        {
          title: "操作",
          key: "createTime",
          width: 120,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            
            return h("div", [
              
              h(
                "a",
                {
                  on: {
                    click: () => {
                      this.edit(params.row)
                    },
                  },
                },
                "修改"
              )
            ]);
          },
        },
      ],
      data: [],
    };
  },
  methods: {
    init() {
      this.getIdenTypeData()
      
    },
   changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      getScRuleGuideByCondition(this.searchForm).then(res => {
        this.loading = false
        if (res.success) {
          // this.data = res.result
          this.data = res.result.content;
          this.total = res.result.totalElements;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      })
    },
    getIdenTypeData() {
      getIdenType().then(res => {
        if (res.success) {
          this.idenList = res.result
          this.getDataList()
        }
      }).catch(() =>{
        this.getDataList()
      })
    },
    add() {
      this.showType = "2";
      this.showUser = true;
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    edit(v) {
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
          v[attr] = "";
        }
        if(typeof v[attr] == 'number') {
          v[attr] = v[attr].toString()
        }
      }
      let str = JSON.stringify(v);
      let data = JSON.parse(str);
      this.form = data;
      this.showType = "1";
      this.showUser = true;
    },
    
    cancel() {

    },
    ok() {

    }
  },
  created() {
  },
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
  },
};
</script>